
<template>
  <div>
    <el-table :border="true" :data="dataSource">
      <el-table-column type="index" label="#" fixed />
      <el-table-column prop="yearTarget_name" label="简称" fixed>
      </el-table-column>
      <el-table-column
        prop="businessIncomeTotalIndex"
        width="180"
        label="年度营业收入指标(万元)"
      >
      </el-table-column>
      <el-table-column
        prop="businessIncomeTotal"
        label="本年累计营业收入(万元)"
      >
      </el-table-column>
      <el-table-column
        prop="annualOperatingRevenueCompletionRate"
        label="年度营业收入完成率"
      >
      </el-table-column>
      <el-table-column prop="netProfitTotalIndex" label="年度净利润指标(万元)">
      </el-table-column>
      <el-table-column prop="netProfitTotal" label="本年累计净利润(万元)">
      </el-table-column>
      <el-table-column
        prop="annualNetProfitCompletionRate"
        label="年度净利润完成率"
      >
      </el-table-column>
    </el-table>
  </div>
</template>
  
  <script>
export default {
  props: ["tableData"],
  watch: {
    tableData: {
      handler() {
        this.countTotal();
      },
      deep: true,
    },
  },
  data() {
    return {
      dataSource: [],
    };
  },
  methods: {
    countTotal() {
      let tableData = this.tableData || [];
      let totalObj = {
        businessIncomeTotalIndex: 0,
        businessIncomeTotal: 0,
        // annualOperatingRevenueCompletionRate:0, 年度收入完成率
        netProfitTotalIndex: 0,
        netProfitTotal: 0,
        // annualNetProfitCompletionRate:0 利润完成率
      };
      tableData.forEach((item, index) => {
        for (let key in totalObj) {
          totalObj[key] = totalObj[key] + (item[key] || 0);
        }
      });
      totalObj["yearTarget_name"] = "汇总";
      totalObj["annualOperatingRevenueCompletionRate"] =
        (totalObj.businessIncomeTotal / totalObj.businessIncomeTotalIndex) *
        100;
      totalObj["annualNetProfitCompletionRate"] =
        (totalObj.netProfitTotal / totalObj.netProfitTotalIndex) * 100;
      let dataSource = [...tableData];
      dataSource.push(totalObj);
      this.dataSource = dataSource;
      // this.tableData.push(totalObj)
      console.log("tableData---------", dataSource);
    },
  },
};
</script>
  
  <style>
</style>